<template>
	<view class="index_content_basic">
		<view class="index_content_basic_main">
			<el-form :model="ruleForm" :rules="rules" label-position="top" ref="ruleForm" label-width="100px"
				class="demo-ruleForm">
				<el-form-item label="填写说明:" prop="">
					<text class="fontz fonts12 gray">未婚/离异填父母、兄弟姐妹；已婚填配偶、子女</text>
				</el-form-item>
				<el-form-item label="称谓" prop="title">
					<el-input v-model="ruleForm.title" placeholder="请输入称谓"></el-input>
				</el-form-item>
				<el-form-item label="姓名" prop="fullName">
					<el-input v-model="ruleForm.fullName" placeholder="请输入姓名"></el-input>
				</el-form-item>
				<el-form-item label="出生年月" prop="">
					<el-date-picker type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss"  placeholder="请选择出生年月" v-model="ruleForm.brithDay" style="width: 100%;">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="政治面貌" prop="">
					<el-select v-model="ruleForm.politicalOutlook" placeholder="请选择政治面貌" style="width: 100%;">
						<el-option v-for="item in politicalOutlookOption" :label="item.dictLabel" :value="item.dictValue">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="工作单位及职位" prop="">
					<el-input v-model="ruleForm.workUnitAndPosition" placeholder="请输入工作单位及职位"></el-input>
				</el-form-item>
				<el-form-item label="联系方式" prop="">
					<el-input v-model="ruleForm.contactInformation" placeholder="请输入联系方式"></el-input>
				</el-form-item>
			</el-form>
		</view>
		<view class="position_footer flex aic jcsb">
			<el-button class="blue_btn" style="width: 100%;" type="primary" @click="submitForm('ruleForm')">保存</el-button>
		</view>
	</view>
</template>

<script>
	import {
		editResume
	} from "@/api/my.js"
	export default {
		data() {
			return {
				ruleForm: {},
				rules: {
					title: [{
						required: true,
						message: '请输入称谓',
						trigger: 'blur'
					}],
					fullName: [{
						required: true,
						message: '请输入姓名',
						trigger: 'blur'
					}],
				},
				indexValue: "",
				type: 0,
				politicalOutlookOption:[]
			};
		},
		onLoad(options) {
			this.politicalOutlookOption= uni.getStorageSync("political_outlook")
			this.datas = JSON.parse(options.data)
			this.type = options.type
			if (options.type == 0) { //修改
				this.indexValue = options.index
				this.info(this.datas, options.index)
			} else { //新增	
			}
		
		},
		methods: {
			info(data, index) {
				console.log("data:", data);
				this.ruleForm = data.familyMembers[index]
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let obj = this.datas
						console.log("数据：",obj);
						if (this.type == 0) {
							obj.familyMembers[this.indexValue] = this.ruleForm
						} else {
							obj.familyMembers.push(this.ruleForm)
						}
			
						editResume(obj).then(res => {
							uni.showToast({
								title: "保存成功",
								icon: 'success'
							})
							if (this.type == 1) {
								uni.navigateBack("-1")
							}
						}).catch(res => {
							uni.showToast({
								title: res.msg,
								icon: 'error'
							})
						})
					} else {
						this.$message({
							message: '请完善信息',
							type: 'error',
							offset: 0.1
						});
						console.log('error submit!!');
						return false;
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.blue_btn {
		height: 40px;
		background: #2F6CBC;
		border: 1px solid #2F6CBC;
	}
</style>
